import {Form, Select} from "antd";
import BaseEntity from "@/type/BaseEntity";
import InputProps from "@/common/form/porps";
import type {Rule} from "rc-field-form/lib/interface";
import type { SelectProps } from 'antd';
import React, {useEffect} from "react";

interface IProps<T extends BaseEntity> extends InputProps<T>{
    options: SelectProps['options'] | string
}

const InputSelect = <T extends BaseEntity>(props: IProps<T>) => {
    const [loading, setLoading] = React.useState(true);
    useEffect(() => {
        if (props.options instanceof Array){
            setLoading(false);
        }else {
            // TODO: 异步加载options
            setLoading(false);
        }
    },[]);
    const rules: Rule[] = [
        {
            required: props.required,
            message: `请选择${props.label}值!`
        },
    ];
    return (
        <Form.Item<T> name={props.name as any} label={props.label} required={props.required} rules={rules}>
            <Select loading={loading} disabled={loading} options={[{value: "1", label: "a"},{value: "2", label: "b"}]}/>
        </Form.Item>

    );
}

export default InputSelect;